#include<cstdio>
#include<iostream>
#include<cstring>
const int maxn=1010;
const double EPS=1e-8;
double dp[maxn][maxn],p[maxn][maxn][3];
int n,m;
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				for(int k=0;k<=2;k++)
					scanf("%lf",&p[i][j][k]);
		memset(dp,0,sizeof(dp));
		dp[n][m]=0;
		for(int i=n;i>=1;i--)
			for(int j=m;j>=1;j--)
			{
				if(i==n&&j==m)continue;
				if(1-p[i][j][0]<=EPS)
				{
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=(p[i][j][0]+p[i][j][1]*(dp[i][j+1]+1)+p[i][j][2]*(dp[i+1][j]+1))/(1-p[i][j][0]);
			}
		printf("%0.3lf\n",dp[1][1]*2);
	}
	return 0;
}

